<script type="text/javascript">

 
$("#example").dialog();

 
function delAction()
{

	var ids = [];
	var el = $("#ids[type=checkbox]").filter(":checked");
	el.each(function(){
		ids.push(   $(this).val()   );
		$(this).parent().parent().fadeOut(500);
	});

	$.getJSON(url("users/delete"),{'ids':ids},function(date){
		
$.jGrowl(date.message);
		});

	return false;
}

function onAjaxSuccess(data)
{
	$.jGrowl(data);
}

function setApproved(obj)
{
	var currentApprovedValue = $(obj).parent().parent().attr('approved') ;
	var currentApprovedId = $(obj).parent().parent().attr('idn') ;
	$(obj).fadeOut(500,function (){

		var newValue;
		if (currentApprovedValue=="0") 
		{
			$(this).find('img').attr('src',url("img/D.jpg"));
		
		}else
		{

			$(this).find('img').attr('src',url("img/A.jpg"));	
		}
		var newAttrValue = (currentApprovedValue=="1")?"0":"1";
		
		$(obj).parent().parent().attr('approved',newAttrValue);
		
		$(obj).fadeIn();
		$.getJSON("<?=$this->baseUrl('users/set-approved');?>",{'id':currentApprovedId, 'value':newAttrValue},onAjaxSuccess);
		})
		
}

function checkAll()
	{$("#ids[type=checkbox]").attr("checked","checked");}
	
function unCheck()
{$("#ids[type=checkbox]").removeAttr("checked");}

function checkInvert()
{
	
	$("#ids[type=checkbox]").each(
			function(){
				if ($(this).attr("checked") )
				{
					$(this).removeAttr("checked");
				}else
				{
				$(this).attr("checked","checked");}
				}
)
}

function onAjaxSuccess(data)
{
	$.jGrowl(data);
}

function setBann(obj)
{
	var currentBannValue = $(obj).parent().parent().attr('bann') ;
	var currentBannId = $(obj).parent().parent().attr('idn') ;
	$(obj).fadeOut(500,function (){

		var newValue;
		if (currentBannValue=="0") 
		{
			$(this).find('img').attr('src',url("img/U.jpg"));
		
		}else
		{

			$(this).find('img').attr('src',url("img/B.jpg"));	
		}
		var newAttrValue = (currentBannValue=="1")?"0":"1";
		
		$(obj).parent().parent().attr('bann',newAttrValue);

		$(obj).fadeIn();
		$.getJSON("<?=$this->baseUrl('users/set-bann');?>",{'id':currentBannId, 'value':newAttrValue},onAjaxSuccess
				);
		})

		$(obj).blur();
		
}
//-->
</script>
<form class='test' method="post" action="<?=$this->baseUrl('users/delete');?>">
<div align="right">

<input type="submit" name='delete' value='Удалить' onclick="return delAction()">
<input type="button" name='add' value='Добавить' onclick="window.location.href='<?=$this->baseUrl('users/add')?>'">
</div>
<br/><br/>
<table style="text-align: center;" cellpadding="10px" width="720px" id='odd' name='table'>
	<tr>
		<td>#</td>
		<td>Имя</td>
		<td>Фамилия</td>
		<td>Логин</td>
		<td>Подтверждение</td>
		<td>Бан</td>
		<td>Удалить</td>
	</tr>
	<?php
$AllUsers = $this->users;
$count = 0;
foreach ( $AllUsers as $Item ):
	$count++;
	$href = $this->baseUrl('users/edit/id/' . $Item['id']);
	$Approved = $Item['Approved'];
	$Bann = $Item['Bann'];
	$idn = $Item['id'];
	
	$Picture = $Approved? $this->baseUrl('img/D.jpg') :$this->baseUrl('img/A.jpg');
	$bannPicture = $Bann?$this->baseUrl('img/U.jpg') :$this->baseUrl('img/B.jpg'); 
	
?>
<tr approved="<?=$Approved;?>" bann="<?=$Bann;?>" idn="<?=$idn;?>">
<td> <?=$count;?> </td>
<td> 
<a href = "<?=$href;?>"> <?=$Item['FirstName'];?> </a> </td>
<td> <?=$Item['LastName'];?> </td>
<td> <?=$Item['Login'];?> </td>

<td> 

<a href='#' onclick="setApproved(this)">
<img alt="" src="<?=$Picture;?>">
</a> 

</td>
<td> <a href='#' onclick="setBann(this)"> 
<img border="none" alt="" src="<?=$bannPicture;?>"></a>
 </td>
<td> 
<input id="ids" type="checkbox" name='ids[]' value="<?=$Item['id']?>"> 
</td>
</tr>
<?php 
endforeach;
?>
</table>
<br /><br />
<div align="right">
<a href="#" onclick="checkAll();return false;"> Выбрать все </a>&nbsp
<a href="#" onclick="unCheck();return false;"> Отменить все </a>&nbsp
<a href="#" onclick="checkInvert();return false;"> Обратить </a>
</div>
<?php 

?>

</form>












